import { BasicColumn, BasicTable, FormSchema, useTable } from "@/components/Table";

import { depositHistoryApi } from "@/api/Hospitalization/hospitalizationExpenses/depositHistory";
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
const index = ({ patientId, page }: any) => {
	const { t } = useTranslation();
	const en_vi = "Hospitalization.Hospitalization.depositHistory";
	const schemas: FormSchema[] = [
		{
			label: t(`${en_vi}.paymentType`),
			field: "pmtType",
			component: "Select",
			componentProps: {
				options: [
					{
						label: t(`${en_vi}.cash`),
						value: 1
					},
					{
						label: t(`${en_vi}.alipay`),
						value: 2
					},
					{
						label: t(`${en_vi}.wechat`),
						value: 3
					}
				]
			}
		},
		{
			label: t(`${en_vi}.orderId`),
			field: "orderId",
			component: "Input"
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.patientId`),
			dataIndex: "patId"
		},
		{
			title: t(`${en_vi}.patCardno`),
			dataIndex: "patCardno"
		},
		{
			title: t(`${en_vi}.paymentType`),
			dataIndex: "pmtType",
			render: (text: any) => {
				if (text == 1) return t(`${en_vi}.cash`);
				if (text == 2) return t(`${en_vi}.alipay`);
				if (text == 3) return t(`${en_vi}.wechat`);
				return t(`${en_vi}.others`);
			}
		},
		{
			title: t(`${en_vi}.paymentAmountCny`),
			dataIndex: "pmtFee",
			render: (text: any, record: any) => {
				if (record.feeType == 2) return "-" + text;
				return text;
			}
		},
		{
			title: t(`${en_vi}.incomeExpenseType`),
			dataIndex: "feeType",
			render: (text: any) => {
				if (text == 1) return t(`${en_vi}.recharge`);
				if (text == 2) return t(`${en_vi}.withdrawal`);
				return t(`${en_vi}.others`);
			}
		},
		{
			title: t(`${en_vi}.orderId`),
			dataIndex: "orderId"
		}
	];
	const [register, { reload }] = useTable({
		api: depositHistoryApi.depositHistoryList,
		columns,
		useSearchForm: true,
		formConfig: {
			labelWidth: 120,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 12 },
			actionColOptions: { span: 24 }
		},
		bordered: false,
		beforeFetch: async params => {
			console.log(params);
			return {
				...params,
				patientId
			};
		}
	});
	useEffect(() => {
		if (page === "1") reload();
	}, [page]);
	return <BasicTable register={register}></BasicTable>;
};
export default index;
